﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AXImServer
{
    public class EncryptionHelper
    {
        private static EncryptionHelper encryption_helper = new EncryptionHelper();

        private EncryptionHelper() { }

        public static EncryptionHelper GetInstance()
        {
            return encryption_helper;
        }

        private Dictionary<string, Func<string, string>> name_2_func = new Dictionary<string, Func<string, string>>();

        /// <summary>
        /// 注册加密类型
        /// </summary>
        /// <param name="type"></param>
        /// <param name="func"></param>
        public void RegisterEncryptionType(string type, Func<string, string> func)
        {
            name_2_func[type] = func;
        }

        /// <summary>
        /// 数据加密
        /// </summary>
        /// <param name="type">加密类型</param>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Encryption(string type, string data)
        {
            Debug.Assert(name_2_func.ContainsKey(type), string.Format("Not find EncryptionType {0}", type));

            var func = name_2_func[type];
            return func(data);
        }
    }
}
